//引入string-random
const stringRandom = require("string-random");
const {User} = require('../../../models/User');

module.exports = async (req, res) => {
	const {user_id,consignee,phoneNumber,area,detailAddress,postalCode} = req.body;
    var add_no = stringRandom(8, { numbers: true });
    try{
    const update = await User.updateOne({user_id:user_id},
    { $addToSet : { "receivingAddress": [{add_no:add_no,consignee:consignee,phoneNumber:phoneNumber,
    area:area,detailAddress:detailAddress,postalCode:postalCode}] } });
    res.send({errCode:'0',msg:"地址添加成功"});
    }catch(e){
        res.status(400).send({errCode:"1",msg:"修改失败"})
    }
}